﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BuildingForm
{
    public partial class DelExistPerson : Form
    {
        public DelExistPerson()
        {
            InitializeComponent();
            Init();
        }
 
        private void Init()
        {
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.ShowIcon = false;
            //表头加粗，居中
            foreach (DataGridViewColumn col in this.dataGridView1.Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            this.dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            this.dataGridView1.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.dataGridView1.AllowUserToAddRows = false;
            this.timer1.Interval = 10;
            this.timer1.Tick += new EventHandler(timer1_Tick);
            this.timer1.Start();
            label2.Text = label1.Text;
            label2.Top = label1.Top;
            label2.Left = this.ClientRectangle.Width;
            label1.Left = 0;


            Maticsoft.DAL.BlackPersons per = new Maticsoft.DAL.BlackPersons();
            Maticsoft.DAL.Ry_Info info = new Maticsoft.DAL.Ry_Info();
            DataTable dt = per.GetList("").Tables[0];
            List<string> strList = new List<string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strList.Add(dt.Rows[i]["nsfzh"].ToString().Trim());
            }
            string str = String.Join("','", strList.ToArray());
            string sql = " sfzh in ( '" + str + "' )";
            DataTable dt2 = info.GetList(sql).Tables[0];
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = dt2;
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            ScrollText();
        }
        private void ScrollText()
        {
            label1.Left -= 1;
            label2.Left -= 1;
            if (label1.Left == 0)
            {
                label2.Left = this.ClientRectangle.Width;
            }
            if (label2.Left == 0)
            {
                label1.Left = this.ClientRectangle.Width;
            }
        }    
    
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            if (MessageBox.Show("您确定要删除吗？", "提示：", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
            {
                if (this.dataGridView1.Columns[e.ColumnIndex].Name == "btnDel")
                {
                    DataGridViewRow r = dataGridView1.Rows[e.RowIndex];
                    string code = r.Cells[2].Value.ToString();
                    Maticsoft.DAL.Ry_Info info = new Maticsoft.DAL.Ry_Info();
                    bool isT = info.Delete(code);
                    if (isT)
                    {
                        MessageBox.Show("删除成功！");
                        Init();
                    }
                    else
                    {
                        MessageBox.Show("删除失败！");
                    }
                }
            }
        }
    }
}
